<?php
switch($_POST["cmd"]) {
case "primary":
	switch($_POST["detail"]) {
	case "add":
		// add new task
		$data = "cmd=task_add\n";
		$network->send($data);
		while($from = $network->recv()) {
			if(strpos($from, "task_add_reply") !== false) {
				break;
			}
		}
		$pm->init($from, "|");
		$task_id = $pm->get("id");

		// set details of new task
		$network->send("cmd=task_set|id=$task_id|data=todo_count|value=1\n");
		$network->send("cmd=task_set|id=$task_id|data=block_size|value=200000\n");
		$network->send("cmd=task_set|id=$task_id|data=timeout|value=30\n");

		$network->send("cmd=task_set|id=$task_id|data=db_user|value=dispatch\n");
		$network->send("cmd=task_set|id=$task_id|data=db_pass|value=dispatchpw\n");
		$network->send("cmd=task_set|id=$task_id|data=db_name|value=dispatch\n");
		$network->send("cmd=task_set|id=$task_id|data=db_host|value=tloyd-ser\n");
		$network->send("cmd=task_set|id=$task_id|data=db_port|value=3306\n");
	
		$network->send("cmd=task_set|id=$task_id|data=todo|value=primary\n");
		$network->send("cmd=task_set|id=$task_id|data=action|value=add\n");

		$network->send("cmd=task_start|id=$task_id\n");
		break;
	case "start":
		// add new task
		$data = "cmd=task_add\n";
		$network->send($data);
		while($from = $network->recv()) {
			if(strpos($from, "task_add_reply") !== false) {
				break;
			}
		}
		$pm->init($from, "|");
		$task_id = $pm->get("id");

		// set details of new task
		$network->send("cmd=task_set|id=$task_id|data=todo_count|value=1\n");
		$network->send("cmd=task_set|id=$task_id|data=block_size|value=1000\n");
		$network->send("cmd=task_set|id=$task_id|data=timeout|value=30\n");

		$network->send("cmd=task_set|id=$task_id|data=db_user|value=dispatch\n");
		$network->send("cmd=task_set|id=$task_id|data=db_pass|value=dispatchpw\n");
		$network->send("cmd=task_set|id=$task_id|data=db_name|value=dispatch\n");
		$network->send("cmd=task_set|id=$task_id|data=db_host|value=tloyd-ser\n");
		$network->send("cmd=task_set|id=$task_id|data=db_port|value=3306\n");

		$network->send("cmd=task_set|id=$task_id|data=todo|value=primary\n");
		$network->send("cmd=task_set|id=$task_id|data=action|value=start\n");
		$network->send("cmd=task_set|id=$task_id|data=value|value=1000\n");

		$network->send("cmd=task_start|id=$task_id\n");
		break;
	}
	break;
}
?>
